package com.itheima.web.interceptor;

import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author huyoufu <https://github.com/huyoufu>
 * @TIME 2020-08-14 20:13
 * @description
 *
 * 实现springmvc 框架提供拦截器
 *
 */


public class MyInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("这里面的代码运行在handler之前的........");

        HandlerMethod handlerMethod= (HandlerMethod) handler;
        System.out.println("正在运行的业务方法哪个对象的:"+handlerMethod.getBean());
        System.out.println("正在运行的业务方法是:"+handlerMethod.getMethod());
        //返回值 代表是否放行!!!
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        System.out.println("方法正常运行之后....");
    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        System.out.println("handler是否 反正我都运行!!!!!");
    }
}
